<!--会员管理-->
<template>
  <div id="memberUser" class="app-container">
    <!--搜索条件-->
    <div class="filter-container">
      <el-form :model="listQuery" :inline="true">
        <el-form-item>
          <el-input v-model="listQuery.keyword" clearable placeholder="请输入关键字" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" plain @click="handleFilter">搜索</el-button>
          <el-button icon="el-icon-refresh" plain @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--列表-->
    <div class="table-container flex-main">
      <div class="table-container-header">
        <table-toolbar :create="false" :remove="false" @refresh="handleFilter">
          <template slot="rightTool">
            <export-drop-down class-name="memberUser" :list-query="listQuery" title="会员" />
          </template>
        </table-toolbar>
      </div>
      <el-table
        ref="multipleTable"
        :data="list"
        header-cell-class-name="table-header"
        fit
        height="100%"
        highlight-current-row
        @selection-change="handleSelectionChange"
        @row-click="handleRowClick"
        @sort-change="sortChange">
        <el-table-column type="selection" width="60" />
        <el-table-column align="center" prop="id" label="#" width="60">
          <template slot-scope="scope">{{ scope.$index+1 }}</template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="头像" prop="avatar" width="70" align="center">
          <template slot-scope="scope">
            <img :src="common.getFileView(scope.row.avatar)" class="common-round-image-32" :title="scope.row.realName" @error="handleImageError">
          </template>
        </el-table-column>
        <el-table-column label="昵称" prop="nickName" width="150" show-overflow-tooltip />
        <el-table-column label="手机号" prop="mobile" width="100" show-overflow-tooltip />
        <el-table-column label="姓名" prop="realName" width="100" show-overflow-tooltip />
        <el-table-column label="余额" prop="wallet" min-width="100" show-overflow-tooltip>
          <template slot-scope="scope">
            <span class="color-danger common-cursor" style="font-size: 15px;font-weight: bold;" @click="handleUpdate(scope.row)">{{ scope.row.wallet |formatPrice }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination_handler">
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData" />
    </div>

    <!--新增/编辑侧边栏-->
    <side-box :show="sideBox.recordShow" title="钱包明细" width="80%" @close="sideBox.recordShow = !sideBox.recordShow">
      <template slot="body">
        <walletChange :member-id="memberUserRecord.id" />
      </template>
    </side-box>
  </div>
</template>

<script>
import walletChange from '@/views/member/walletChange'
export default {
  components: { walletChange },

  data() {
    return {
      list: [],
      total: 0,
      listQuery: {
        page: 1,
        limit: this.common.PAGE_LIMIT_DEFAULT,
        keyword: undefined,
        sort: this.common.SORT_DEFAULT
      },

      multipleSelectionRecords: [],
      // 固定写法
      sideBox: {
        recordShow: false,
        title: '钱包明细',
        status: 'create'
      },
      memberUserRecord: {}
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // 表格自带方法开始
    /* 全选/反选*/
    handleSelectionChange(val) {
      this.multipleSelectionRecords = val
    },
    /* 表格行数据单击*/
    handleRowClick(row) {
      this.$refs.multipleTable.toggleRowSelection(row)
    },
    /* 表格列排序*/
    sortChange(data) {
      const { prop, order } = data
      if (prop) {
        if (order === 'ascending') {
          this.listQuery.sort = '+' + prop
        } else {
          this.listQuery.sort = '-' + prop
        }
      } else {
        this.listQuery.sort = this.common.SORT_DEFAULT
      }
      this.handleFilter()
    },
    // 表格自带方法结束

    /* 搜索*/
    handleFilter() {
      this.listQuery = {
        ...this.listQuery,
        page: 1
      }
      this.fetchData()
    },
    /* 重置*/
    handleReset() {
      this.listQuery = {
        ...this.listQuery,
        page: 1,
        limit: this.common.PAGE_LIMIT_DEFAULT,
        keyword: undefined,
        sort: this.common.SORT_DEFAULT
      }
      this.$refs.multipleTable.clearFilter()
      this.$refs.multipleTable.clearSort()
      this.fetchData()
    },
    async fetchData() {
      const response = await this.$store.dispatch('memberUserPage', this.listQuery)
      this.list = response.records
      this.total = response.total
    },
    /* 编辑*/
    handleUpdate(row) {
      this.memberUserRecord = Object.assign({}, row) // copy obj
      this.sideBox = {
        recordShow: true
      }
    }
  }
}
</script>
    <style lang="scss" scoped>
    </style>
